{include file="public/layout"/}
<body class="rolecss bodystyle" style=" overflow-y: scroll;min-width:auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="system/left" /}
<style type="text/css">
    .none {display: none !important;}
</style>
<div class="page min-hg-c-10" style="min-width:auto;margin-left:100px;">
    <div class="flexigrid htitx">
        <div id="" class="explanation">
            <ul>
                <li>以下收款接口，本系统仅提供API接入服务，收款平台的可靠性请自行斟酌!</li>
                <li>收款接口选用，有相关执照的商家推荐使用官方接口。个人用户推荐使用虎皮椒</li>
            </ul>
        </div>
        <form id="postConfig" data-url="{:url('PayApi/pay_api_config', ['_ajax' => 1])}">
            <div class="ncap-form-default" id="accordions">
                <div class="hDiv">
                    <div class="hDivBox">
                        <table cellspacing="0" cellpadding="0" style="width: 100%">
                            <thead><tr><th axis="col0"><div class="text-l10">接口设置</div></th></tr></thead>
                        </table>
                    </div>
                </div>

                <dl class="row">
                    <dt class="tit"><label>微信收款接口</label></dt>
                    <dd class="opt">
                        <label class="curpoin">
                            <input type="radio" name="pay[pay_wechat_open]" value="1" {if condition="!empty($userConfig.pay_wechat_open) && 1 === intval($userConfig.pay_wechat_open)"}checked="checked"{/if} onclick="payWeChatOpen(1);">微信官方
                        </label>
                        &nbsp; &nbsp;
                        <label class="curpoin">
                            <input type="radio" name="pay[pay_wechat_open]" value="2" {if condition="!empty($userConfig.pay_wechat_open) && 2 === intval($userConfig.pay_wechat_open)"}checked="checked"{/if} onclick="payWeChatOpen(2);">虎皮椒支付-微信
                        </label>
                        &nbsp; &nbsp;
                        <label class="curpoin">
                            <input type="radio" name="pay[pay_wechat_open]" value="0" {if condition="empty($userConfig.pay_wechat_open)"}checked="checked"{/if} onclick="payWeChatOpen(0);">关闭微信收款
                        </label>
                    </dd>
                </dl>
                <script type="text/javascript">
                    function payWeChatOpen(value) {
                        // 微信官方
                        if (1 === parseInt(value)) {
                            $('#wechatPay').show();
                            $('#hupijiaoPay').hide();
                            $('.wechat').removeClass('none');
                        }
                        // 虎皮椒支付-微信
                        else if (2 === parseInt(value)) {
                            $('#wechatPay').hide();
                            $('#hupijiaoPay').show();
                            $('.wechat').addClass('none');
                        }
                        // 关闭微信收款
                        else {
                            $('#wechatPay, #hupijiaoPay').hide();
                            $('.wechat').addClass('none');
                        }
                    }
                </script>
                {if condition="$php_servicemeal >= 2"}
                <dl class="row">
                    <dt class="tit"><label>余额支付</label></dt>
                    <dd class="opt">
                        <label class="curpoin">
                            <input type="radio" name="pay[pay_balance_open]" value="1" {if condition="!empty($userConfig.pay_balance_open)"}checked="checked"{/if}>开启
                        </label>
                        &nbsp;
                        <label class="curpoin">
                            <input type="radio" name="pay[pay_balance_open]" value="0" {if condition="empty($userConfig.pay_balance_open)"}checked="checked"{/if}>关闭
                        </label>
                    </dd>
                </dl>
                {/if}
                <div class="mb15 some-parent-class">
                    <div class="hDiv api_poplistdiv">
                        <div class="hDivBox">
                            <table cellspacing="0" cellpadding="0" style="width: 100%">
                                <thead>
                                    <tr>
                                        <th axis="col0">
                                            <div class="curpoin">
                                                <a class="links" style="color: #555; margin-left: 10px;"><i class="fa fa-angle-right"></i>微信配置</a>
                                            </div>
                                        </th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <div class="api_poplistdiv_down" id="wechatPay" {if condition="empty($userConfig.pay_wechat_open) || 1 !== intval($userConfig.pay_wechat_open)"}style="display: none;"{/if}>
                        <dl class="row">
                            <div class="explanation">
                                <ul>
                                    <li>
                                        <a href="JavaScript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=8829&origin_eycms=1', '微信支付配置教程')" >微信支付配置教程</a>
                                    </li>
                                </ul>
                            </div>
                            <dd class="opt">
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="mchid"><em class="wechat {notempty name='$wechat.is_open_wechat'}none{/notempty}">*</em>微信商户号</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[wechat][mchid]" id="mchid" value="{$wechat.mchid|default=''}" class="input-txt" autocomplete="off">
                                        <p class="notic2">微信支付平台商户号 <a href="https://pay.weixin.qq.com/index.php/extend/pay_setting" target="_blank">[产品中心]-[开发配置]-[商户号]</a></p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="key"><em class="wechat {notempty name='$wechat.is_open_wechat'}none{/notempty}">*</em>APIv2密钥</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[wechat][key]" id="key" value="{$wechat.key|default=''}" class="input-txt" autocomplete="off">
                                        <p class="notic2">微信支付平台APIv2密钥 <a href="https://kf.qq.com/faq/180830UVRZR7180830Ij6ZZz.html" target="_blank">查看教程</a></p>
                                    </dd>
                                </dl>
                                <input type="file" id="apiclientClickID" onchange="apiclientClick(this);" style="display: none;">
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="apiclient_cert"><em class="wechat {notempty name='$wechat.is_open_wechat'}none{/notempty}">*</em>apiclient_cert</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="hidden" name="config[wechat][apiclient_cert]" id="apiclient_cert" value="{$wechat.apiclient_cert|default=''}">
                                        <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" onclick="$('#apiclientClickID').attr('data-type', 'apiclient_cert').trigger('click');">{empty name="$wechat.apiclient_cert"}点击上传{else/}重新上传{/empty}</a>
                                        <span style="{empty name='$wechat.apiclient_cert'}display: none;{/empty} color: red;">上传成功</span>
                                        <p class="notic2">请上传已申请证书中的 apiclient_cert.pem文件</p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="apiclient_key"><em class="wechat {notempty name='$wechat.is_open_wechat'}none{/notempty}">*</em>apiclient_key</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="hidden" name="config[wechat][apiclient_key]" id="apiclient_key" value="{$wechat.apiclient_key|default=''}">
                                        <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" onclick="$('#apiclientClickID').attr('data-type', 'apiclient_key').trigger('click');">{empty name="$wechat.apiclient_key"}点击上传{else/}重新上传{/empty}</a>
                                        <span style="{empty name='$wechat.apiclient_key'}display: none;{/empty} color: red;">上传成功</span>
                                        <p class="notic2">请上传已申请证书中的 apiclient_key.pem文件</p>
                                        <p class="notic2">微信支付平台API证书 <a href="https://kf.qq.com/faq/161222NneAJf161222U7fARv.html" target="_blank">查看教程</a></p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit"><label>验证支付配置</label></dt>
                                    <dd class="opt">
                                        <label class="curpoin">
                                            <input type="radio" name="pay[pay_verify_config]" value="1" onclick="$('#payChannel').show();" {notempty name="$userConfig.pay_verify_config"} checked {/notempty}>是
                                        </label>
                                        &nbsp; &nbsp;
                                        <label class="curpoin">
                                            <input type="radio" name="pay[pay_verify_config]" value="0" onclick="$('#payChannel').hide();" {empty name="$userConfig.pay_verify_config"} checked {/empty}>否
                                        </label>
                                    </dd>
                                </dl>
                                <dl class="row" id="payChannel" {empty name="$userConfig.pay_verify_config"} style="display: none;" {/empty}>
                                    <dt class="tit"></dt>
                                    <dd class="opt">
                                        <label class="curpoin">
                                            <input type="checkbox" name="pay[pay_verify_gzh]" value="1" {notempty name="$userConfig.pay_verify_gzh"} checked {/notempty}>微信公众号支付配置
                                        </label>
                                        &nbsp; &nbsp;
                                        <label class="curpoin">
                                            <input type="checkbox" name="pay[pay_verify_xcx]" value="1" {notempty name="$userConfig.pay_verify_xcx"} checked {/notempty}>微信小程序支付配置
                                        </label>
                                    </dd>
                                </dl>
                            </dd>
                        </dl>
                    </div>
                </div>

                <div class="mb15 some-parent-class">
                    <div class="hDiv api_poplistdiv">
                        <div class="hDivBox">
                            <table cellspacing="0" cellpadding="0" style="width: 100%">
                                <thead>
                                    <tr>
                                        <th axis="col0">
                                            <div class="curpoin">
                                                <a class="links" style="color: #555;margin-left: 10px;"><i class="fa fa-angle-right"></i>虎皮椒配置</a>
                                            </div>
                                        </th>
                                    </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <div class="api_poplistdiv_down" id="hupijiaoPay" {if condition="empty($userConfig.pay_wechat_open) || 2 !== intval($userConfig.pay_wechat_open)"}style="display: none;"{/if}>
                        <dl class="row">
                            <div class="explanation">
                                <ul>
                                    <li>
                                        <a href="JavaScript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=10167','虎皮椒支付配置教程')">虎皮椒支付配置教程</a>
                                    </li>
                                </ul>
                            </div>
                            <!-- <dt class="tit pt10">虎皮椒支付</dt> -->
                            <dd class="opt">
                                <!-- <dl class="row">
                                    <dt class="tit">
                                        <label for="alipay_appid">支付宝AppId</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[hupijiaoPay][alipay_appid]" id="alipay_appid" value="{$hupijiaoPay.alipay_appid}" class="input-txt">
                                        <p class="notic">请输入您的虎皮椒的支付宝AppId，用于支付。</p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="alipay_appsecret">支付宝AppSecret</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[hupijiaoPay][alipay_appsecret]" id="alipay_appsecret" value="{$hupijiaoPay.alipay_appsecret}" class="input-txt">
                                        <p class="notic">请输入您的虎皮椒的支付宝AppSecret，用于支付。</p>
                                    </dd>
                                </dl> -->
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="wechat_appid">微信AppId</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[hupijiaoPay][wechat_appid]" id="wechat_appid" value="{$Hupijiaopay.wechat_appid}" class="input-txt">
                                        <p class="notic">请输入您的虎皮椒的微信AppId，用于支付。</p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="wechat_appsecret">微信AppSecret</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[hupijiaoPay][wechat_appsecret]" id="wechat_appsecret" value="{$Hupijiaopay.wechat_appsecret}" class="input-txt">
                                        <p class="notic">请输入您的虎皮椒的微信AppSecret，用于支付。</p>
                                    </dd>
                                </dl>
                                <dl class="row">
                                    <dt class="tit">
                                        <label for="gateway_domain">支付网关域名</label>
                                    </dt>
                                    <dd class="opt">
                                        <input type="text" name="config[hupijiaoPay][gateway_domain]" id="gateway_domain" value="{$Hupijiaopay.gateway_domain}" class="input-txt" placeholder="例如：https://api.xunhupay.com">
                                        <p class="notic">请填写你申请支付通道的平台的域名</p>
                                    </dd>
                                </dl>
                            </dd>
                        </dl>
                    </div>
                </div>

                <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" onclick="submitConfig();">确认提交</a></div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    $(function() {  
        var Accordion = function(el, multiple) {  
            this.$el = el;  
            this.multiple = multiple || false;  
            this.$el.on('click', '.links', this.dropdown.bind(this));  
        };  
        Accordion.prototype.dropdown = function(event) {  
            event.preventDefault();  
            var $next = $(event.target).closest('.some-parent-class').find('.api_poplistdiv_down');  
            $next.slideToggle();  
            $next.closest('.some-parent-class').toggleClass('open');  
        };  
        var accordion = new Accordion($('#accordions'), false);

        var to = "{$Request.param.sys}";
        if (to) {
            var div_top = document.getElementById(to).offsetTop;
            window.scrollTo(0, div_top + 70);
        }
        //右侧浮动点击定位到相应模块
        var lis = document.getElementsByClassName("event");
        for(var i = 0; i < lis.length; i++) {
            lis[i].onclick = function() {
                //获取当前event的data-to属性值，用来匹配目标div
                var attr = this.getAttribute("data-to");
                //获取与当前event想匹配的div距离页面顶端的距离
                var div_top = document.getElementById(attr).offsetTop;
                window.scrollTo(0, div_top + 70);
            }
        }
    });

    // 表单提交
    function submitConfig() {
        layer_loading('正在处理');
        $.ajax({
            type: "POST",
            url : $('#postConfig').data('url'),
            data: $('#postConfig').serialize(),
            dataType: 'json',
            success: function (res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    showSuccessMsg(res.msg, 1000, function() {
                        window.location.reload();
                    });
                } else {
                    showErrorAlert(res.msg);
                }
            },
            error: function(e) {
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }

    // 文件上传
    function apiclientClick(obj) {
        // 获取文件路径名
        var file = $(obj)[0].files[0];
        var type = $(obj).attr('data-type');
        var full_name = type ? type + '.pem' : '';
        // 验证上传的文件
        if (full_name == 'apiclient_cert.pem' && full_name != file.name) {
            console.log('jinqu1');
            $(obj).val('');
            showErrorAlert('apiclient_cert 只允许上传 apiclient_cert.pem 文件');
            return false;
        } else if (full_name == 'apiclient_key.pem' && full_name != file.name) {
            console.log('jinqu2');
            $(obj).val('');
            showErrorAlert('apiclient_key 只允许上传 apiclient_key.pem 文件');
            return false;
        }
        // 验证上传格式
        var fileName = file.name;
        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
        var ext = judgeExt(fileExt);
        if (ext == -1) {
            showErrorAlert('不支持选中的文件格式');
            return false;
        }
        // 验证上传大小
        var size = "{$upload_max_filesize}";
        if (file.size > size) {
            showErrorAlert('文件大小超过服务器限制');
            return false;
        }
        // 定义上传数据
        var formData = new FormData();
        formData.append('file', file);
        // 执行上传
        layer_loading('上传本地');
        $.ajax({
            type: 'post',
            url : "{:url('PayApi/file_upload')}",
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            xhr: function () {
                myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {
                    myXhr.upload.addEventListener('progress', function(e) {
                        var curr = e.loaded;
                        var total = e.total;
                        process = parseInt(curr / total * 100);
                        $('#' + type).parent().find('a').html('上传中...'+process+"%");
                    });
                }
                return myXhr;
            },
            success: function (res) {
                $(obj).val('');
                layer.closeAll();
                $('#' + type).parent().find('a').html('重新上传');
                if (1 === parseInt(res.code)) {
                    $('#' + type).val(res.data.file_url);
                    $('#' + type).parent().find('span').show();
                } else {
                    showErrorAlert(res.msg);
                }
            }
        });
    }

    // 验证格式
    function judgeExt(ext) {
        var type = "{$file_type}";
        var extArr = [];
        extArr = type.split("|");
        var ext = ext.replace(".", "");
        return extArr.indexOf(ext);
    }
</script>

{include file="public/footer" /}
